package com.fdb.efp.batch.service.impl;

import com.fdb.basic.framework.core.base.FrameworkService;
import com.fdb.basic.framework.core.util.DateTool;
import com.fdb.basic.framework.core.util.DateUtility;
import com.fdb.efp.batch.common.constant.BdLoanConstant;
import com.fdb.efp.batch.service.facade.LoanSettleRepayDetailHandleService;
import com.fdb.efp.loan.common.LoanConstant;
import com.fdb.efp.loan.service.facade.*;
import com.fdb.efp.loan.service.vo.*;
import com.fdb.efp.nls.service.facade.NlsApplyInfoService;
import com.fdb.efp.nls.service.vo.NlsApplyInfoVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * <p>
 * ServiceImpl: 马上理赔还款明细表
 * <p>
 * 
 * @author cyj
 * @date 2018-12-27
 */
@Service("loanSettleRepayDetailHandleService")
public class LoanSettleRepayDetailHandleServiceImpl implements LoanSettleRepayDetailHandleService, FrameworkService {

	private static Logger logger = LoggerFactory.getLogger(LoanSettleRepayDetailHandleServiceImpl.class);

	@Autowired
	@Qualifier("gzBankSettleRepayDetailFileTempService")
	private GzBankSettleRepayDetailFileTempService gzBankSettleRepayDetailFileTempService;
	
	@Autowired
	@Qualifier("settleDetailAccountTempService")
	private SettleDetailAccountTempService settleDetailAccountTempService;
	
	@Autowired
	@Qualifier("accoutErroTempService")
	private AccoutErroTempService accoutErroTempService;
	
	@Autowired
	@Qualifier("accLoanService")
	private AccLoanService accLoanService;
	
	@Autowired
	@Qualifier("loanRepayDetailService")
	private LoanRepayDetailService loanRepayDetailService;
	
	@Autowired
	@Qualifier("nlsApplyInfoService")
	private NlsApplyInfoService nlsApplyInfoService;// 网贷申请基本信息

	/**
	 * 
	 * 同步马上的数据 新增 理赔还款明细表 <br>
	 * 0.2:ludayong:2019年3月6日 下午5:10:56:修复理赔还款明细临时信息为空时，出现空指针异常<br>
	 * @author cenyj
	 * @since 2018年12月28日 下午3:33:37
	 * @date 2019年3月6日 下午5:10:56
	 * @version 0.2
	 */
	public boolean batchLoanSettleRepayDetailFromMaTxt() throws Exception {
		boolean rs = false;
		try {
			// 分页大小
			Integer pageSize = 1000;
			// 分页信息
			GzBankSettleRepayDetailFileTempVO pageInfo = new GzBankSettleRepayDetailFileTempVO();
			// 页数
			int page = 1;
			// pageSize初始化
			if (pageSize > 0) {
				pageInfo.setSize(pageSize);
			} else {
				pageInfo.setSize(1000);
			}
			// 判断循环次数
			int size = gzBankSettleRepayDetailFileTempService.queryCount();
			String size_msg = "【理赔还款明细信息表临时表】数据量：" + size;
			logger.info(size_msg, "message{}");
			int loopCount = (size / pageInfo.getSize()) + 1;

			// 对账数据
//			Double payPrincipalAmt = 0.0;
//			Double actualPayPrincipalAmt = 0.0;
//			Double payinterestamt = 0.0;
//			Double actualPayInterestAmt = 0.0;
//			Double payPrincipalPenaltyAmt = 0.0;
//			Double actualPayPrincipalPenaltyAmt = 0.0;
            BigDecimal payPrincipalAmtSum = BigDecimal.ZERO;
            BigDecimal actualPayPrincipalAmtSum = BigDecimal.ZERO;
            BigDecimal payinterestamtSum = BigDecimal.ZERO;
            BigDecimal actualPayInterestAmtSum = BigDecimal.ZERO;
            BigDecimal payPrincipalPenaltyAmtSum = BigDecimal.ZERO;
            BigDecimal actualPayPrincipalPenaltyAmtSum = BigDecimal.ZERO;
			for (int i = 0; i < loopCount; i++) {
				String page_msg = "【理赔还款明细信息表临时表】当前页数：" + pageInfo.getPage() + "，分页大小：" + pageInfo.getSize();
				logger.info(page_msg, "message{}");
				// 分页查询【理赔还款明细信息表临时表】数据
				List<GzBankSettleRepayDetailFileTempVO> tempList = gzBankSettleRepayDetailFileTempService.queryByPage(pageInfo);
				if (Objects.nonNull(tempList) && !tempList.isEmpty()) {
					// 分页同步理赔还款明细信息
					syncSettleRepayDetailInfo(tempList);
//					payPrincipalAmt += tempList.stream().mapToDouble(GzBankSettleRepayDetailFileTempVO::getPayPrincipalAmt).sum();
//					actualPayPrincipalAmt += tempList.stream().mapToDouble(GzBankSettleRepayDetailFileTempVO::getActualPayPrincipalAmt).sum();
//					payinterestamt += tempList.stream().mapToDouble(GzBankSettleRepayDetailFileTempVO::getPayInterestAmt).sum();
//					actualPayInterestAmt += tempList.stream().mapToDouble(GzBankSettleRepayDetailFileTempVO::getActualPayInterestAmt).sum();
//					payPrincipalPenaltyAmt += tempList.stream().mapToDouble(GzBankSettleRepayDetailFileTempVO::getPayPrincipalPenaltyAmt).sum();
//					actualPayPrincipalPenaltyAmt += tempList.stream().mapToDouble(GzBankSettleRepayDetailFileTempVO::getActualPayPrincipalPenaltyAmt).sum();
                    payPrincipalAmtSum = payPrincipalAmtSum.add(tempList.stream().map(GzBankSettleRepayDetailFileTempVO::getPayPrincipalAmt).filter(Objects::nonNull).map(s -> new BigDecimal(String.valueOf(s)))
                            .reduce(BigDecimal.ZERO, BigDecimal::add));
                    actualPayPrincipalAmtSum = actualPayPrincipalAmtSum.add(tempList.stream().map(GzBankSettleRepayDetailFileTempVO::getActualPayPrincipalAmt).filter(Objects::nonNull).map(s -> new BigDecimal(String.valueOf(s)))
                            .reduce(BigDecimal.ZERO, BigDecimal::add));
                    payinterestamtSum = payinterestamtSum.add(tempList.stream().map(GzBankSettleRepayDetailFileTempVO::getPayInterestAmt).filter(Objects::nonNull).map(s -> new BigDecimal(String.valueOf(s)))
                            .reduce(BigDecimal.ZERO, BigDecimal::add));
                    actualPayInterestAmtSum = actualPayInterestAmtSum.add(tempList.stream().map(GzBankSettleRepayDetailFileTempVO::getActualPayInterestAmt).filter(Objects::nonNull).map(s -> new BigDecimal(String.valueOf(s)))
                            .reduce(BigDecimal.ZERO, BigDecimal::add));
                    payPrincipalPenaltyAmtSum = payPrincipalPenaltyAmtSum.add(tempList.stream().map(GzBankSettleRepayDetailFileTempVO::getPayPrincipalPenaltyAmt).filter(Objects::nonNull).map(s -> new BigDecimal(String.valueOf(s)))
                            .reduce(BigDecimal.ZERO, BigDecimal::add));
                    actualPayPrincipalPenaltyAmtSum = actualPayPrincipalPenaltyAmtSum.add(tempList.stream().map(GzBankSettleRepayDetailFileTempVO::getActualPayPrincipalPenaltyAmt).filter(Objects::nonNull).map(s -> new BigDecimal(String.valueOf(s)))
                            .reduce(BigDecimal.ZERO, BigDecimal::add));
				}
				pageInfo.setPage(++page);
			}

			// 先 对账表，看是否能对应上
			//logger.info("日终批量修改从马上同步过来的临时表数据到还款明细表：");
			// 先校对 对账临时表的记录条数跟同步过来的数据是否一致 如果一致 再批量 把临时表的数据同步到本地
			// 临时表
			//List<GzBankSettleRepayDetailFileTempVO> list = gzBankSettleRepayDetailFileTempService.getGzBankSettleRepayDetailFileTempList();
			//同步信息为空，返回false
			//if(Objects.isNull(list)) {
			//	logger.info("日终批量-同步马上的贷款理赔还款明细为空！");
			//	return rs;
			//}
			
			// 对账临时表列表
			List<SettleDetailAccountTempVO> accountList = settleDetailAccountTempService.getSettleDetailAccountTempList();
			// 对账临时表
			SettleDetailAccountTempVO accountTempModel = null;//new SettleDetailAccountTempVO();
			// 临时表列表的sum
//			Double payPrincipalAmt = list.stream().mapToDouble(GzBankSettleRepayDetailFileTempVO::getPayPrincipalAmt).sum();
//			Double actualPayPrincipalAmt = list.stream().mapToDouble(GzBankSettleRepayDetailFileTempVO::getActualPayPrincipalAmt).sum();
//			Double payinterestamt = list.stream().mapToDouble(GzBankSettleRepayDetailFileTempVO::getPayInterestAmt).sum();
//			Double actualPayInterestAmt = list.stream().mapToDouble(GzBankSettleRepayDetailFileTempVO::getActualPayInterestAmt).sum();
//			Double payPrincipalPenaltyAmt = list.stream().mapToDouble(GzBankSettleRepayDetailFileTempVO::getPayPrincipalPenaltyAmt).sum();
//			Double actualPayPrincipalPenaltyAmt = list.stream()
//					.mapToDouble(GzBankSettleRepayDetailFileTempVO::getActualPayPrincipalPenaltyAmt).sum();
//			BigDecimal payPrincipalAmtSum = BigDecimal.valueOf(payPrincipalAmt == null ? 0 : payPrincipalAmt);
//			BigDecimal actualPayPrincipalAmtSum = BigDecimal.valueOf(actualPayPrincipalAmt == null ? 0 : actualPayPrincipalAmt);
//			BigDecimal payinterestamtSum = BigDecimal.valueOf(payinterestamt == null ? 0 : payinterestamt);
//			BigDecimal actualPayInterestAmtSum = BigDecimal.valueOf(actualPayInterestAmt == null ? 0 : actualPayInterestAmt);
//			BigDecimal payPrincipalPenaltyAmtSum = BigDecimal.valueOf(payPrincipalPenaltyAmt == null ? 0 : payPrincipalPenaltyAmt);
//			BigDecimal actualPayPrincipalPenaltyAmtSum = BigDecimal
//					.valueOf(actualPayPrincipalPenaltyAmt == null ? 0 : actualPayPrincipalPenaltyAmt);

			// 對賬裏面的值
			int accountCountTemp = 0;// 对账表记录的条数
			int loanTempDatasize = 0;// 实际同步过来的数据总条数
			if (accountList != null && accountList.size() > 0) {
				accountTempModel = accountList.get(0);
			}
			if (accountTempModel != null) {
				accountCountTemp = accountTempModel.getDataAcount() == null ? 0 : accountTempModel.getDataAcount();
				String tableName = "GzBankSettleRepayDetailFileTemp";
				if (accountTempModel.getPayPrincipalAmtTotal().compareTo( payPrincipalAmtSum) !=0) {
					String erroMsg = "应还本金总额getPayPrincipalAmtTotal不对";
					String  acountTotal= "" + accountTempModel.getPayPrincipalAmtTotal();
					String  tempTotal= "" + payPrincipalAmtSum;
					accoutErroTempService.accountErroMsg(tableName, erroMsg, tempTotal, acountTotal, "1", "", "", "");
				}
				if (accountTempModel.getActualPayPrincipalAmtTotal().compareTo( actualPayPrincipalAmtSum) !=0) {
					String erroMsg = "还款本金总额getActualPayPrincipalAmtTotal不对";
					String  acountTotal= "" + accountTempModel.getActualPayPrincipalAmtTotal();
					String  tempTotal= "" + actualPayPrincipalAmtSum;
					accoutErroTempService.accountErroMsg(tableName, erroMsg, tempTotal, acountTotal, "1", "", "", "");
				}
				if (accountTempModel.getPayinterestamtTotal().compareTo( payinterestamtSum) !=0) {
					String erroMsg = "应还利息总额getPayinterestamtTotal不对";
					String  acountTotal= "" + accountTempModel.getPayinterestamtTotal();
					String  tempTotal= "" + payinterestamtSum;
					accoutErroTempService.accountErroMsg(tableName, erroMsg, tempTotal, acountTotal, "1", "", "", "");
				}
				if (accountTempModel.getActualPayinterestAmtTotal().compareTo( actualPayInterestAmtSum) !=0) {
					String erroMsg = "还款利息总额getActualPayinterestAmtTotal不对";
					String  acountTotal= "" + accountTempModel.getActualPayinterestAmtTotal();
					String  tempTotal= "" + actualPayInterestAmtSum;
					accoutErroTempService.accountErroMsg(tableName, erroMsg, tempTotal, acountTotal, "1", "", "", "");
				}
				if (accountTempModel.getPayPrincipalPenaltyAmtTotal().compareTo( payPrincipalPenaltyAmtSum) !=0) {
					String erroMsg = "应还罚息总额getPayPrincipalPenaltyAmtTotal不对";
					String  acountTotal= "" + accountTempModel.getPayPrincipalPenaltyAmtTotal();
					String  tempTotal= "" + payPrincipalPenaltyAmtSum;
					accoutErroTempService.accountErroMsg(tableName, erroMsg, tempTotal, acountTotal, "1", "", "", "");
				}
				if (accountTempModel.getActualPayPrincipalPenaltyAmtTotal().compareTo( actualPayPrincipalPenaltyAmtSum) !=0) {
					String erroMsg = "还款罚息总额getActualPayPrincipalPenaltyAmtTotal不对";
					String  acountTotal= "" + accountTempModel.getActualPayPrincipalPenaltyAmtTotal();
					String  tempTotal= "" + actualPayPrincipalPenaltyAmtSum;
					accoutErroTempService.accountErroMsg(tableName, erroMsg, tempTotal, acountTotal, "1", "", "", "");
				}

			}
			//loanTempDatasize = list.size();
			loanTempDatasize = size;
			logger.info("对账表记录的条数loanTempDatasize：" + loanTempDatasize + "实际同步过来的数据总条数loanTempDatasize" + loanTempDatasize);
			if (loanTempDatasize != accountCountTemp) {
				// 如果条数不一样，则记录到erro_msg表
				String erroMsg = "记录条数不对";
				String tableName = "GzBankSettleRepayDetailFileTemp";
				String tempTotal = "" + loanTempDatasize;
				String acountTotal = "" + accountCountTemp;
				accoutErroTempService.accountErroMsg(tableName, erroMsg, tempTotal, acountTotal, "1", "", "", "");
			}
			rs = true;
		} catch (Exception e) {
			logger.error("理赔明细数据发生异常!", e);
			e.printStackTrace();
			String tableName = "LoanSettleRepayDetail理赔明细表";
			String erroMsg = "";
			String tempTotal = "";
			String acountTotal = "";
			String type = "0";
			String updateDelInster = "";
			String no = "";
			String eMsg = e.getMessage();
			accoutErroTempService.accountErroMsg(tableName, erroMsg, tempTotal, acountTotal, type, updateDelInster, no, eMsg);
		}
		return rs;
	}

	/**
	 *需求编号：【2019D1204】（马上账务文件同步分页处理）
	 *问题编号：【2019D1204】（马上账务文件同步分页处理）
	 *开发人员：【ludayong】
	 *创建日期：【2019/11/27 11:31】
	 *功能描述：分页同步理赔还款明细信息
	 *修改日期：【2019/11/27 11:31】
	 *修改描述：
	 */
	public void syncSettleRepayDetailInfo(List<GzBankSettleRepayDetailFileTempVO> list) {
		try {
			// 本地表进行修改INSERT
			if (list != null && list.size() > 0) {
				for (GzBankSettleRepayDetailFileTempVO fileTemp : list) {
					// 因爲有可能出现我们审批没有通过，但马上放款的数据，所以先判断本地借据表是否有对应的借据号 有再新增
					AccLoanVO acc_loan = new AccLoanVO();
					acc_loan.setBillNo(fileTemp.getLoanNo());
					AccLoanVO accLoan = accLoanService.queryByPk(acc_loan);

					NlsApplyInfoVO inNlsApplyInfoVO = new NlsApplyInfoVO();
					inNlsApplyInfoVO.setApplySeq(fileTemp.getLoanNo());
					NlsApplyInfoVO queryNlsApplyInfoVO = nlsApplyInfoService.queryByPk(inNlsApplyInfoVO);// 查询网贷申请基本信息

					if (accLoan != null) {
						// LoanSettleRepayDetail settleModel = new LoanSettleRepayDetail();
						LoanRepayDetailVO settleModel = new LoanRepayDetailVO();
						try {
							SimpleDateFormat sdfTime = new SimpleDateFormat("yyyy-MM-dd");//
							String actualPayDate=DateUtility.format10To10(fileTemp.getActualPayDate());//实还日期  setl_apply_dt  setl_val_dt
							// 还款明细流水号-还款流水号
							//settleModel.setSetlSeq(Integer.valueOf(fileTemp.getPlSerialNo() == null ? "0" : fileTemp.getPlSerialNo()));
							settleModel.setSetlSeq(fileTemp.getPlSerialNo());
							// 贷款借据号-贷款借据号
							settleModel.setLoanNo(fileTemp.getLoanNo());
							// 贷款合同编号 赋值
							settleModel.setContNo(fileTemp.getLoanNo());//queryNlsApplyInfoVO.getApplySeq()
							// 剩余正常本金-剩余本金余额
							settleModel.setPsRemPrcp(BigDecimal.valueOf(fileTemp.getPrincipalBalance()));
							// 还款时总拖欠复利-应还利息罚息
							settleModel.setAllOdCommIntAmt(BigDecimal.valueOf(fileTemp.getPayInterestPenaltyAmt()));
							// 还款时总拖欠罚息-应还本金罚息
							settleModel.setAllOdIntAmt(BigDecimal.valueOf(fileTemp.getPayPrincipalPenaltyAmt()));
							// 还款时总拖欠利息-应还利息
							settleModel.setAllOdNormIntAmt(BigDecimal.valueOf(fileTemp.getPayInterestAmt()));
							// 还款时总拖欠本金-应还本金
							settleModel.setAllOdPrcpAmt(BigDecimal.valueOf(fileTemp.getPayPrincipalAmt()));
							// 归还复利金额-实还利息罚息
							settleModel.setSetlOdCommInt(BigDecimal.valueOf(fileTemp.getActualPayInterestPenaltyAmt()));
							// 归还罚息金额-实还本金罚息
							settleModel.setSetlOdIntAmt(BigDecimal.valueOf(fileTemp.getActualPayPrincipalPenaltyAmt()));
							// 归还欠息金额-实还利息
							settleModel.setSetlOdNormInt(BigDecimal.valueOf(fileTemp.getActualPayInterestAmt()));
							// 归还欠本金额-实还本金
							settleModel.setSetlOdPrcpAmt(BigDecimal.valueOf(fileTemp.getActualPayPrincipalAmt()));
							// 还款账号-入账账号
							settleModel.setDisbAcNo(fileTemp.getInAccountNo());
							//setl_apply_dt  	主动还款申请日期-ActualPayDate	实还日期
							settleModel.setSetlApplyDt(actualPayDate);
							//setl_val_dt	生效日期-ActualPayDate	实还日期
							settleModel.setSetlValDt(actualPayDate);

							// 还款类型：理赔还款类型
							settleModel.setSetlTyp("05");// 赋值-

							String currentTime = DateTool.getCurrentDateTime();// 当前时间 //////////////////////////////
							String createUser = "admin";
							if (queryNlsApplyInfoVO != null) {
								// 客户名称 赋值
								settleModel.setCustName(queryNlsApplyInfoVO.getCusName());
								// 证件类型 赋值
								settleModel.setIdType(queryNlsApplyInfoVO.getCertType());
								// 证件号码 赋值
								settleModel.setIdNo(queryNlsApplyInfoVO.getCertCode());
							}
							// 放款金额 赋值
							// settleModel.setdnamt();
							// int_rat 执行年利率 赋值
							// setl_rem_prcp_paym 提前还本金额 条件输入   理赔类型不赋值
							//20190215 modify cyj
							// 放款金额 赋值 setdnamt
							settleModel.setDnAmt(accLoan.getLoanAmount() == null ? BigDecimal.ZERO : accLoan.getLoanAmount());
							// int_rat 执行年利率 赋值
							settleModel.setIntRat(accLoan.getRealityIrY() == null ? BigDecimal.ZERO : accLoan.getRealityIrY());
							// total_amt 本次还款总计金额 penalty_amt+interest_amt+principal_amt+total_fee
							BigDecimal totalAmt = BigDecimal.valueOf(fileTemp.getActualPayInterestPenaltyAmt())
									.add(BigDecimal.valueOf(fileTemp.getActualPayPrincipalPenaltyAmt()))
									.add(BigDecimal.valueOf(fileTemp.getActualPayInterestAmt()))
									.add(BigDecimal.valueOf(fileTemp.getActualPayPrincipalAmt()));
							settleModel.setTotalAmt(totalAmt);
							// acct_typ 账户类型 对公 对私
							// setl_origin 主动还款渠道 赋值-马上 马上
							settleModel.setSetlOrigin(BdLoanConstant.MS_CHANNEL_NO);
							// setl_create_usr 创建用户 admin admin
							settleModel.setSetlCreateUsr(createUser);
							// setl_create_dt 创建日期 new date new date
							settleModel.setSetlCreateDt(currentTime); ///
							// last_chg_usr 最新变更用户 admin admin
							settleModel.setLastChgUsr(createUser);
							// last_chg_dt 最新变更时间 new date new date
							settleModel.setLastChgDt(currentTime);///
							settleModel.setRepayTerm(fileTemp.getPeriodNo().toString());

							int num = 0;
							//查询还款明细信息是否存在，存在则更新，不存在则新增
							LoanRepayDetailVO queryLoanRepayDetailVO = loanRepayDetailService.queryByPk(settleModel);
							if(Objects.nonNull(queryLoanRepayDetailVO)) {
								//更新还款明细信息
								num = loanRepayDetailService.updateByPk(settleModel);
							}else {
								//新增还款明细信息
								num = loanRepayDetailService.insertLoanRepayDetail(settleModel);
							}

							if (num == -1) {
								logger.error("新增数据信息出错!");
								String tableName = "LoanRepayDetail还款明细表";
								String erroMsg = "";
								String tempTotal = "";
								String acountTotal = "";
								String type = "0";
								String updateDelInster = "新增";
								String no = fileTemp.getLoanNo();
								String eMsg = "新增数据信息出错!";
								accoutErroTempService.accountErroMsg(tableName, erroMsg, tempTotal, acountTotal, type, updateDelInster, no,
										eMsg);
							}else {
								//// 查询还款明细
								LoanRepayDetailVO loanRepayDetailVO=new LoanRepayDetailVO();
								loanRepayDetailVO.setLoanNo(accLoan.getBillNo());
								List<LoanRepayDetailVO>  loanRepayDetailList=
										loanRepayDetailService.queryAllByLoanNo(loanRepayDetailVO);
								// latest_repay_date 最近还款日期 赋值（取还款明细的还款日期？）//getLatestRepayDate
								if (loanRepayDetailList != null) {
									List<LocalDate> list2 = loanRepayDetailList.stream().map(LoanRepayDetailVO::getSetlApplyDt)
											.map(o -> LocalDate.parse(o, DateTimeFormatter.ISO_DATE))
											.sorted().collect(Collectors.toList());
									if(list2 != null && list.size()>0) {
										String lastTime = list2.get(list2.size() - 1).format(DateTimeFormatter.ISO_DATE);
										accLoan.setLatestRepayDate(lastTime);
										//台账状态：结清、理赔结清
										if (LoanConstant.TZZT_LPJQ.equals(accLoan.getAccountStatus())) {
											// // settl_date 结清日期 赋值  结清时： 最近还款日期
											accLoan.setSettlDate(lastTime);
											logger.info("借据表最近还款日期赋值为："+lastTime+"");
										}
									}
									// repayment_account 还款账号最新的 赋值？还款明细 的账号  repay_card_no
									////repay_card_no	disb_ac_no	还款银行卡号setDisbAcNo  getRepayCardNo
									List<String> list3 = loanRepayDetailList.stream().map(LoanRepayDetailVO::getDisbAcNo)
											.collect(Collectors.toList());
									if(list3 != null && list.size()>0) {
										String repaymentAccount = list3.get(list3.size() - 1);
										accLoan.setRepaymentAccount(repaymentAccount);
									}
								}
								num = accLoanService.updateByPk(accLoan);// 更新
								if (num == -1) {
									logger.error("更新数据发生异常");
									String tableName = "AccLoan贷款台账表";
									String erroMsg = "";
									String tempTotal = "";
									String acountTotal = "";
									String type = "0";
									String updateDelInster = "更新";
									String no = fileTemp.getLoanNo();
									String eMsg = "";
									accoutErroTempService.accountErroMsg(tableName, erroMsg, tempTotal, acountTotal, type,
											updateDelInster, no, eMsg);

								}
							}
						} catch (Exception e) {
							logger.error("新增数据发生异常!", e);
							e.printStackTrace();
							String tableName = "LoanRepayDetail还款明细表";
							String erroMsg = "";
							String tempTotal = "";
							String acountTotal = "";
							String type = "0";
							String updateDelInster = "新增";
							String no = fileTemp.getLoanNo();
							String eMsg = e.getMessage();
							accoutErroTempService.accountErroMsg(tableName, erroMsg, tempTotal, acountTotal, type, updateDelInster, no,
									eMsg);

						}
					} else {
						logger.info("没有对应的借据数据信息!");
						String tableName = "LoanSettleRepayDetail理赔明细表";
						String erroMsg = "";
						String tempTotal = "";
						String acountTotal = "";
						String type = "0";
						String updateDelInster = "新增";
						String no = fileTemp.getLoanNo();
						String eMsg = "没有对应的借据数据信息!";
						accoutErroTempService.accountErroMsg(tableName, erroMsg, tempTotal, acountTotal, type, updateDelInster, no, eMsg);
					}
				}

			}
		} catch (Exception e) {
			logger.error("同步马上理赔还款明细信息数据发生异常!", e);
		}
	}
}
